﻿@inherits AdminCompontentBase
<div @ref="Ref">
    <SSheetDialog Value="@_visible" ValueChanged="HandleVisibleChanged" Title="@T("Permission.ViewMessageRecord")">
        <div class="full-height d-flex">
            <div class="pa-12 record-detail-left">
                <DefaultUserAvatar Avatar="@_messageRecord.User.Avatar" Size="48" />
                <div class="h8 emphasis--text mt-2">@(_messageRecord.User.DisplayName)</div>
                <div class="body2 regular--text mt-2">@(_messageRecord.User.Email)</div>
                <div class="body2 regular--text mt-1">@(_messageRecord.User.PhoneNumber)</div>
                <div class="subtitle3 regular--text mt-9">@T("DisplayName.MessageTaskSendTime")</div>
                <MTimeline Dense=false Class="mt-9" Style="margin-left: -66px;">
                    <MTimelineItem Small FillDot Right>
                        <OppositeContent>
                            <span class="body2 regular--text mr-n5">@T("DisplayName.MessageRecordExpectSendTime")</span>
                        </OppositeContent>
                        <IconContent>
                            <MAvatar Color="primary" Size="16"></MAvatar>
                        </IconContent>
                        <ChildContent>
                            <div class="ml-n5">
                                <div class="btn emphasis--text">@(_messageRecord.ExpectSendTime?.ToOffset(JsInitVariables.TimezoneOffset).ToString(T("$DateFormat")))</div>
                                <div class="overline regular3--text">@(_messageRecord.ExpectSendTime?.ToOffset(JsInitVariables.TimezoneOffset).ToString(T("$TimeFormat")))</div>
                            </div>
                        </ChildContent>
                    </MTimelineItem>
                    <MTimelineItem Small FillDot Right Class="mt-5">
                        <OppositeContent>
                            <span class="body2 regular--text mr-n5">@T("DisplayName.MessageRecordSendTime")</span>
                        </OppositeContent>
                        <IconContent>
                            <MAvatar Color="primary" Size="16"></MAvatar>
                        </IconContent>
                        <ChildContent>
                            <div class="ml-n5">
                                <div class="btn emphasis--text">@_messageRecord.SendTime?.ToOffset(JsInitVariables.TimezoneOffset).ToString(T("$DateFormat"))</div>
                                <div class="overline regular3--text">@_messageRecord.SendTime?.ToOffset(JsInitVariables.TimezoneOffset).ToString(T("$TimeFormat"))</div>
                            </div>
                        </ChildContent>
                    </MTimelineItem>
                </MTimeline>
                <div class="subtitle3 regular--text mt-9">@T("DisplayName.MessageRecordResult")</div>
                <div class="mt-9">
                    <dl class="d-flex justify-space-between item align-center mb-6">
                        <dt class="d-inline-flex body2 regular--text">
                            @if (_messageRecord.Success == true)
                            {
                                <span>@T("DisplayName.MessageRecordSuccess.True")</span>
                            }
                            @if (_messageRecord.Success == false)
                            {
                                <span>@T("DisplayName.MessageRecordSuccess.False")</span>
                            }
                        </dt>
                        @if (_messageRecord.Success == false)
                        {
                            <a href="javascript:;" class="body2 primary--text text-decoration-none" @onclick="async() => await Throttle(HandleRetry)">@T("Retry")</a>
                        }
                    </dl>
                    @if (_messageRecord.Success == false)
                    {
                        <dl class="d-flex justify-space-between item align-center mb-6">
                            <dt class="d-inline-flex body2 regular--text">
                                <span>@_messageRecord.FailureReason</span>
                            </dt>
                            <dd class="body2 regular3--text">@T("DisplayName.MessageRecordFailureReason")</dd>
                        </dl>
                    }
                    @if (_messageTaskHistory is not null)
                    {
                        <dl class="d-flex justify-space-between item align-center">
                            <dt class="d-inline-flex body2 regular--text">
                                <span>@_messageTaskHistory.TaskHistoryNo</span>
                            </dt>
                            <dd class="body2 regular3--text">@T("DisplayName.MessageTaskHistoryNo")</dd>
                        </dl>
                    }
                </div>
            </div>
            <MDivider Vertical></MDivider>
            <div class="record-detail-right full-height flex-column">
                <div class="subtitle2 emphasis2--text">@T("DisplayName.MessageInfoContent")</div>
                @if (_messageTask is null)
                {
                    @if (_messageRecord.MessageEntityType == MessageEntityTypes.Ordinary)
                    {
                        <OrdinaryMessageInfoByMessageRecord MessageInfoId="_messageRecord.MessageEntityId" MessageRecord="_messageRecord" />
                    }
                    @if (_messageRecord.MessageEntityType == MessageEntityTypes.Template)
                    {
                        <TemplateMessageInfoByMessageRecord MessageTemplateId="_messageRecord.MessageEntityId" MessageRecord="_messageRecord" Variables="_messageRecord.Variables" IsRender />
                    }
                }
                else{
                    @if (_messageTask.EntityType == MessageEntityTypes.Ordinary)
                    {
                        <OrdinaryMessageInfo MessageInfoId="_messageTask.EntityId" MessageTask="_messageTask" />
                    }
                    @if (_messageTask.EntityType == MessageEntityTypes.Template)
                    {
                        <TemplateMessageInfo MessageTemplateId="_messageTask.EntityId" MessageTask="_messageTask" Variables="_messageRecord.Variables" IsRender />
                    }
                }
            </div>

        </div>
    </SSheetDialog>
</div>